#ifndef MUSICPLAYER_H
#define MUSICPLAYER_H

#include <QWidget>
#include "QUrl"
#include "QListWidgetItem"
#include "PlayMode.h"
#include "ui_MusicPlayer.h"

QT_BEGIN_NAMESPACE
class QAudioOutput;
class QMediaPlayer;
namespace Ui {
class MusicPlayer;
}
QT_END_NAMESPACE

class MusicPlayer : public QWidget
{
    Q_OBJECT

public:
    MusicPlayer(QWidget *parent = nullptr);
    ~MusicPlayer();

private slots:
    void on_pushButton_file_clicked();

    void on_pushButton_switch_clicked();

    void on_pushButton_lastsong_clicked();

    void on_pushButton_nextsong_clicked();

    void on_listWidget_musiclist_doubleClicked(const QModelIndex &index);

    void on_horizontalSlider_volume_valueChanged(int value);

    void on_pushButton_volume_clicked();

    void on_pushButton_mode_clicked();

    void on_listWidget_musiclist_customContextMenuRequested(const QPoint &pos);

    void on_listWidget_collection_customContextMenuRequested(const QPoint &pos);

    void on_listWidget_collection_doubleClicked(const QModelIndex &index);

    void on_pushButton_musiclist_clicked();

    void on_pushButton_collection_clicked();

    void on_pushButton_home_clicked();

private:
    Ui::MusicPlayer *ui;
    QList<QUrl> playList; // 播放列表
    QList<QUrl> collectionList; // 收藏列表
    QAudioOutput* audioOutput;
    QMediaPlayer* mediaPlayer;
    int volume = 30; // 初始音量
    int curPlayIndex = 0; // 播放下标
    playMode currentPlayMode = playMode::Sequential; // 播放模式

    void setPlayMode(playMode newMode);
    void playSong(QListWidgetItem *item);
    void addToFavorites(QListWidgetItem *item);
    void deleteFavorites(QListWidgetItem *item);
};
#endif // MUSICPLAYER_H

